#import "RootViewController.h"
#import "XMLAppDelegate.h"
#import "XMLParser.h"
#import "PlayView.h"
#import "PlayerView.h"

@implementation PlayView





- (IBAction)switchToPlayer
{
	if([servertxt.text length]>0){
		NSString *servertext = servertxt.text;
		NSLog(@"got to switch %@",servertext);
		PlayerView *playerView =[[PlayerView alloc]initWithNibName:@"PlayerView" bundle:[NSBundle mainBundle]];
		playerView.servertext = servertext;
		NSLog(playerView.servertext);
		[self.navigationController pushViewController:playerView animated:YES];
		

	}
	else
		Status.text = @"Connection Failed";
		

}


- (IBAction)switchTosequence
{
	NSLog(@"test");
		NSString *fail = @"Connection failed";
		NSString *server = [[NSString alloc] initWithFormat:@"http://%@:41402/request.html?action=list&type=sequence",servertxt.text];
		NSURL *url = [[NSURL alloc] initWithString:server];
		NSXMLParser *xmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
	
	//Initialize the delegate.
	XMLParser *parser = [[XMLParser alloc] initXMLParser];
	
	//Set delegate
	[xmlParser setDelegate:parser];
	
	//Start parsing the XML file.
	BOOL success = [xmlParser parse];
	
	if(success){
		NSLog(@"No Errors");
		NSLog(@"server: %@",server);
		rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:[NSBundle mainBundle]];
		[self.navigationController pushViewController:rootViewController animated:YES];
	}
	else
		Status.text = fail;
	
	
	

	
}

- (void)viewDidLoad {
    [super viewDidLoad];
	
	self.title = @"Main";
}

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField {
	
	[theTextField resignFirstResponder];
	return	YES;
}

@end
